package com.douwong.student.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.douwong.student.R;
import com.douwong.student.model.PrepareTitle;

import java.util.ArrayList;

public class PrepareDetailAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<PrepareTitle> list;

	public PrepareDetailAdapter(Context context, ArrayList<PrepareTitle> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder=null;
		if (convertView == null) {
			holder=new Holder();
			convertView=LayoutInflater.from(context).inflate(R.layout.prepaer_detail_item, null);
			holder.imgView=(ImageView) convertView.findViewById(R.id.daodu_img);
			holder.name_text=(TextView) convertView.findViewById(R.id.name_text);
			convertView.setTag(holder);
		}else {
			holder=(Holder) convertView.getTag();
		}
		if(list.size()>0){
			holder.imgView.setImageResource(getIdByType(list.get(position).getType()));
			holder.name_text.setText(list.get(position).getName());
		}
		return convertView;
	}

	class Holder {
		ImageView imgView;
		TextView name_text;
	}
	private int getIdByType(int type){
		switch (type) {
		case 1:
			type=R.mipmap.daodu;
			break;
		case 2:
			type=R.mipmap.test;
			break;
		case 3:
			type=R.mipmap.job;
			break;
		default:
			break;
		}
		return type;
		
	}
}
